实验六

2023-05-16

芯片派生

#include<iostream>
using namespace std;
class Base{
    public:
        void add(int x,int y) {
            cout<<x<<" + "<<y<<" = "<<x+y<<endl;
        }   
};
class A:public Base{
    public:
        void subt(int x,int y){
            cout<<x<<" - "<<y<<" = "<<x-y<<endl;
        }
};
class B:public Base{
    public:
        void mult(int x,int y){
            cout<<x<<" * "<<y<<" = "<<x*y<<endl;
        }
};
class C:public Base{
    public:
        void divi(int x,int y){
            cout<<x<<" / "<<y<<" = "<<x/y<<endl;
        }
};
int main(){
    A my_a;
    B my_b;
    C my_c;
    cout<<"Test A  "<<endl; 
    my_a.add(3,5);
    my_a.subt(4,6);
    cout<<"Test B  "<<endl;
    my_b.add(5,8);
    my_b.mult(6,6);
    cout<<"Test C  "<<endl;
    my_c.add(9,9);
    my_c.divi(9,3);
    return 0;
}

1350350-20180604195719472-880648178.png

Vehicle类和派生

#include<iostream>
#include<string>
using namespace std;
class Vehicle{
    public:
        Vehicle(int m,int w):maxspeed(m),weight(w){
            cout<<"Constructing Vehicle!"<<endl;
        }
        void run(){
            cout<<"run"<<endl;
        }
        void stop(){
            cout<<"stop"<<endl;
        }
        int getM()const{
            return maxspeed;
        }
        int getW()const{
            return weight;
        }
        ~Vehicle(){
            cout<<"Destructing Vehicle..."<<endl;
        }
    private:
        int maxspeed;
        int weight;
};
class Bicycle:public virtual Vehicle{
    public:
        Bicycle(double h,int m,int w):height(h),Vehicle(m,w){
            cout<<"Constructing Bicycle!"<<endl;
        }
        double getH()const{
            return height;
        }
        ~Bicycle(){
            cout<<"Destructing Bicycle..."<<endl;
        }
    private:
        double height;
};
class Motorcar:public virtual Vehicle{
    public:
        Motorcar(int s,int m,int w):seatnum(s),Vehicle(m,w){
            cout<<"Constructing Motorcar!"<<endl;
        }
        int getS()const{
            return seatnum;
        }
        ~Motorcar(){
            cout<<"Destructing Motorcar..."<<endl;
        }
    private:
        int seatnum;
};
class Motorcycle:public Bicycle,public Motorcar{
    public:
        Motorcycle(int m,int w,int s,double h):Vehicle(m,w),Bicycle(h,m,w),Motorcar(s,m,w){ 
            cout<<"Constructing Motorcycle!"<<endl;
        }
        void display()const{
            cout<<"maxspeed : "<<getM()<<endl;
            cout<<"weight : "<<getW()<<endl;
            cout<<"height : "<<getH()<<endl;
            cout<<"seatnum : "<<getS()<<endl;
        }
        ~Motorcycle(){
            cout<<"Destructing Motorcycle..."<<endl;
        }
};
int main(){
    Motorcycle my_motor(60,4,3,1.45);
    my_motor.run();
    my_motor.display();
    my_motor.stop();
    return 0;
}

1350350-20180604195842147-1087237969.png

iFraction

Fraction我用的是上次的代码

  • Fraction.h
#ifndef FRACTION_H_
#define FRACTION_H_
#include<string>
#include<iostream>
using namespace std;
class Fraction
{
    int top, bottom;
    string show;
public:
    Fraction(int t=0, int b = 1);
    ~Fraction();
    friend Fraction operator +(Fraction &f1,Fraction &f2);//重载“+”运算符,用于计算两个分数相加
    friend Fraction operator +( int num, Fraction &f);//重载“+”运算符,用于一个整数与分数相加
    friend Fraction operator -(Fraction &f1,Fraction &f2);//重载“-”运算符,用于计算两个分数相减
    friend Fraction operator -( int num, Fraction &f);//重载“-”,用于一个整数减去一个分数
    friend Fraction operator *(Fraction &f1,Fraction &f2);//重载“*”
    friend Fraction operator *( int num, Fraction &f);//重载“*”,整数乘分数
    friend Fraction operator /(Fraction &f1,Fraction &f2);//重载“/”
    friend Fraction operator /(int num, Fraction &f);//重载“/”,整数除分数
    bool operator <( Fraction &f);//重载“<”
    friend bool operator <( int num, Fraction  &f);//重载“<”,整数与分数比较
    bool operator >( Fraction &f);//重载“>”
    friend bool operator >( int num, Fraction &f);//重载“>”,整数与分数比较
    void setdata();//重新设置
    void display();//显示分数
    int getTop()const;
    int getBottom()const;
    string getshow();
    friend void convertF(Fraction& f);
};
#endif
  • Fraction.cpp
#include "stdafx.h"
#include "Fraction.h"
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int Common_divisor(int top, int bottom)//用于求公约数
{
    int common_divisor;
    while (1)
    {
        if (top%bottom == 0)
        {
            return bottom;
        }
        else {
            common_divisor= bottom;
            bottom = top % common_divisor;
            top = common_divisor;
        }
    }
    return common_divisor;
}
bool limited(int bottom) {   //用来判断一个分数是否可以化为有限小数输出
    if (bottom == 1)
    {
        return true;
    }
    else if(bottom % 2 == 0)
    {
        return limited(bottom / 2);
    }
    else if (bottom % 5 == 0)
    {
        return limited(bottom / 5);
    }
    else {
        return false;
    }
}
//在构造分数时,直接按照要求进行修整,方便后面计算
Fraction::Fraction(int t,int b):top(t),bottom(b),show(""){ 
    if (top < 0 && bottom < 0)//分子分母都小于零,去符号
    {
        top = -top;
        bottom = -bottom;
    }
    if (bottom < 0 && top>0)//分母小于零,分子大于零,交换符号
    {
        top = -top;
        bottom = -bottom;
    }
    int temp_t, temp_b;
    if (top < 0)//避免负数进行%运算时的干扰
    {
        temp_t = -top;
        temp_b = bottom;
    }
    else {
        temp_t = top;
        temp_b = bottom;
    }
    bottom = bottom / Common_divisor(temp_t,temp_b);
    top = top / Common_divisor(temp_t,temp_b);
}
//加减乘除操作基本相同,分母不同通分,找公约数,最简化
Fraction operator+ (Fraction &f1,Fraction &f2) {
    int temp_b,temp_t,temp_t_b,temp_t_t;//temp_b,temp_t用来储存通分后的分子分母,temp_t_b,temp_t_t用于计算公约数
    if (f1.bottom != f2.bottom)//分母不同时,通分
    {
        temp_b= f1.bottom * f2.bottom;
        temp_t=f1.top * f2.bottom+f2.top*f1.bottom;
        if (temp_t < 0)//防止负数干扰求公约运算
        {
            temp_t_t = -temp_t;
            temp_t_b = temp_b;
        }
        else {
            temp_t_t = temp_t;
            temp_t_b = temp_b;
        }
        return Fraction(temp_b/ Common_divisor(temp_t_t,temp_t_b),temp_t/ Common_divisor(temp_t_t,temp_t_b));//通分后除于公约数
    }
    else {//分母相同,分子直接相加
        temp_b = f1.bottom;
        temp_t = f1.top+f2.top;
        if (temp_t < 0)
        {
            temp_t_t = -temp_t;
            temp_t_b = temp_b;
        }
        else {
            temp_t_t = temp_t;
            temp_t_b = temp_b;
        }
        return Fraction(temp_b/ Common_divisor(temp_t_t,temp_t_b),temp_t/ Common_divisor(temp_t_t,temp_t_b));
    }
}
Fraction operator +(int num, Fraction &f) {
    int temp_b, temp_t, temp_t_t; //temp_t用来储存通分后的分子,temp_b, temp_t_t用于计算公约数
    temp_b = f.bottom;
    temp_t = num * f.bottom + f.top;
    if (temp_t < 0)//防止负数干扰求公约运算
    {
        temp_t_t = -temp_t;
    }
    else {
        temp_t_t = temp_t;
    }
    return Fraction(temp_t / Common_divisor(temp_t_t, temp_b), temp_b / Common_divisor(temp_t_t, temp_b));
}
Fraction operator -(Fraction &f1,Fraction &f2) {
    int temp_b, temp_t, temp_t_b, temp_t_t; //temp_b, temp_t用来储存通分后的分子分母,temp_t_b, temp_t_t用于计算公约数
    if (f1.bottom != f2.bottom)
    {
        temp_b = f1.bottom * f2.bottom;
        temp_t = f1.top * f2.bottom - f2.top*f1.bottom;
        if (temp_t < 0)//防止负数干扰求公约运算
        {
            temp_t_t = -temp_t;
            temp_t_b = temp_b;
        }
        else {
            temp_t_t = temp_t;
            temp_t_b = temp_b;
        }
        return Fraction(temp_b / Common_divisor(temp_t_t,temp_t_b),temp_t / Common_divisor(temp_t_t,temp_t_b));
    }
    else {
        temp_b = f1.bottom;
        temp_t = f1.top - f2.top;
        if (temp_t < 0)//防止负数干扰求公约运算
        {
            temp_t_t = -temp_t;
            temp_t_b = temp_b;
        }
        else {
            temp_t_t = temp_t;
            temp_t_b = temp_b;
        }
        return Fraction(temp_b/ Common_divisor(temp_t_t,temp_t_b),temp_t/ Common_divisor(temp_t_t,temp_t_b));
    }
}
Fraction operator -(int num, Fraction &f)
{
    int temp_b, temp_t, temp_t_t; //temp_t用来储存通分后的分子,temp_b, temp_t_t用于计算公约数
    temp_b = f.bottom;
    temp_t = num * f.bottom - f.top;
    if (temp_t < 0)//防止负数干扰求公约运算
    {
        temp_t_t = -temp_t;
    }
    else {
        temp_t_t = temp_t;
    }
    return Fraction(temp_t / Common_divisor(temp_t_t, temp_b), temp_b / Common_divisor(temp_t_t, temp_b));
}
Fraction operator *(Fraction &f1,Fraction &f2) {
    int temp_b, temp_t, temp_t_b, temp_t_t;//temp_b,temp_t用来互乘后分子分母,temp_t_b,temp_t_t用于计算公约数
    temp_b = f1.bottom * f2.bottom;
    temp_t = f1.top * f2.top;
    if (temp_t < 0)//防止负数干扰求公约运算
    {
        temp_t_t = -temp_t;
        temp_t_b = temp_b;
    }
    else {
        temp_t_t = temp_t;
        temp_t_b = temp_b;
    }
    return Fraction(temp_b / Common_divisor(temp_t_t,temp_t_b),temp_t / Common_divisor(temp_t_t,temp_t_b));
}
Fraction operator *(int num, Fraction &f) {
    int temp_b, temp_t, temp_t_t; //temp_t用来储存通分后的分子,temp_b, temp_t_t用于计算公约数
    temp_b = f.bottom;
    temp_t = num *f.top;
    if (temp_t < 0)//防止负数干扰求公约运算
    {
        temp_t_t = -temp_t;
    }
    else {
        temp_t_t = temp_t;
    }
    return Fraction(temp_t / Common_divisor(temp_t_t, temp_b), temp_b / Common_divisor(temp_t_t, temp_b));
}
Fraction operator / (Fraction &f1,Fraction &f2) {
    int temp_b, temp_t, temp_t_b, temp_t_t;//temp_b,temp_sum用来储存乘倒数后的分子分母,temp_t_b,temp_t_sum用于计算公约数
    temp_t = f1.top * f2.bottom;
    temp_b = f1.bottom * f2.top;
    if (temp_t < 0)//防止负数干扰求公约运算
    {
        temp_t_t = -temp_t;
        temp_t_b = temp_b;
    }
    else {
        temp_t_t = temp_t;
        temp_t_b = temp_b;
    }
    return Fraction(temp_b / Common_divisor(temp_t_t,temp_t_b),temp_t / Common_divisor(temp_t_t,temp_t_b));
}
Fraction operator / (int num, Fraction &f){
    int temp_b, temp_t, temp_t_t; //temp_t用来储存通分后的分子,temp_b, temp_t_t用于计算公约数
    temp_b = f.top;
    temp_t = num * f.bottom;
    if (temp_t < 0)//防止负数干扰求公约运算
    {
        temp_t_t = -temp_t;
    }
    else {
        temp_t_t = temp_t;
    }
    return Fraction(temp_t / Common_divisor(temp_t_t, temp_b), temp_b / Common_divisor(temp_t_t, temp_b));
}
bool Fraction::operator > (Fraction &f){
    if (bottom == f.bottom)
    {
        if (top > f.top)
        {
            return true;
        }
        else {
            return false;
        }
    }
    else
    {
        int temp_t, temp_ft;
        temp_t = top * f.bottom;
        temp_ft = f.top*bottom;
        if (temp_t > temp_ft)
        {
            return true;
        }
        else {
            return false;
        }
    }
}
bool operator >(int num,Fraction &f){
    if (num*f.bottom > f.top)
    {
        return true;
    }
    else {
        return false;
    }
}
bool Fraction::operator < (Fraction &f) {
    if (bottom == f.bottom)
    {
        if (top <f.top)
        {
            return true;
        }
        else {
            return false;
        }
    }
    else
    {
        int temp_t, temp_ft;
        temp_t = top * f.bottom;
        temp_ft = f.top*bottom;
        if (temp_t < temp_ft)
        {
            return true;
        }
        else {
            return false;
        }
    }
}
bool operator <(int num,Fraction &f){
    if (num*f.bottom < f.top)
    {
        return true;
    }
    else {
        return false;
    }
}
void Fraction::setdata()
{
    cout << "please enter top:";
    cin >> top;
    cout << "please enter bottom:";
    cin >> bottom;
    if (top < 0 && bottom < 0)
    {
        top = -top;
        bottom = -bottom;
    }
    if (bottom < 0 && top>0)
    {
        top = -top;
        bottom = -bottom;
    }
    int temp_t, temp_b,temp_t_t,temp_t_b;
    temp_t = top;
    temp_b = bottom;
    if (temp_t < 0)//防止负数干扰求公约运算
    {
        temp_t_t = -temp_t;
        temp_t_b = temp_b;
    }
    else {
        temp_t_t = temp_t;
        temp_t_b = temp_b;
    }
    bottom = temp_b / Common_divisor(temp_t_t,temp_t_b);
    top = temp_t / Common_divisor(temp_t_t,temp_t_b);
}
void Fraction::display() {
    if (limited(bottom))
    {
        double Frac_double;
        Frac_double = double(top) / double(bottom);
        cout << Frac_double << endl;
    }
    else
    {
        cout << top << "/" << bottom << endl;
    }
}
int Fraction::getTop()const {
    return top;
}
int Fraction::getBottom()const {
    return bottom;
}
string Fraction::getshow() {
    return show;
}
void convertF(Fraction& f) {
    int t, b, n = 0;
    b = f.bottom;
    if (fabs(f.top) > b)
    {
        n = fabs(f.top) / b;
        t = fabs(f.top) - n * b;
    }
    else {
        t = fabs(f.top);
    }
    if (f.top < 0) {
        f.show.push_back('-');
        f.show.push_back(static_cast<char>(n + 48));
        f.show.push_back(' ');
        f.show.push_back(static_cast<char>(t + 48));
        f.show.push_back('/');
        f.show.push_back(static_cast<char>(b + 48));
    }
    else {
        f.show.push_back(static_cast<char>(n + 48));
        f.show.push_back(' ');
        f.show.push_back(static_cast<char>(t + 48));
        f.show.push_back('/');
        f.show.push_back(static_cast<char>(b + 48));
    }
}
Fraction::~Fraction()
{
}
  • iFraction.h
#include<string>
#include"Fraction.h"
using namespace std;
#ifndef IFRACTION_H_
#define IFRACTION_H_
class iFraction :public Fraction {
    string newshow;
    public:
        iFraction(int t = 0, int b = 1);
        void showstr();
        ~iFraction();
};
#endif 
  • iFraction.cpp
#include<iostream>
#include<string>
#include"iFraction.h"
using namespace std;
iFraction::iFraction(int t,int b):Fraction(t,b){
    convertF(*this);
    newshow = getshow();
}
void iFraction::showstr() {
    cout << newshow<< endl;
}
iFraction::~iFraction(){} 
  • main.cpp
#include "stdafx.h"
#include"Fraction.h"
#include"iFraction.h"
#include<iostream>
using namespace std;
int main()
{
    iFraction  newf1(-5, 3),newf2(15,2),newf3(63,-8);
    convertF(newf1);
    newf1.showstr();
    convertF(newf2);
    convertF(newf3);
    newf2.showstr();
    newf3.showstr();
    return 0;
}

1350350-20180604201559635-294507882.png

小游戏

只是加完了代码和两个类,游戏太多不平衡了,基本打不过电脑.....

  • container.h
//=======================
//      container.h
//=======================
// The so-called inventory of a player in RPG games
// contains two items, heal and magic water
#ifndef _CONTAINER// Conditional compilation
#define _CONTAINER
class container     // Inventory
{
protected:
    int numOfHeal;          // number of heal
    int numOfMW;            // number of magic water
public:
    container();            // constuctor
    void set(int heal_n, int mw_n); // set the items numbers
    int nOfHeal();          // get the number of heal
    int nOfMW();            // get the number of magic water
    void display();         // display the items;
    bool useHeal();         // use heal
    bool useMW();           // use magic water
};
#endif 
  • container.cpp
//=======================
//      container.cpp
//=======================
#include"container.h"
#include<iostream>
using namespace std;
// default constructor initialise the inventory as empty
container::container()
{
    set(0, 0);
}
// set the item numbers
void container::set(int heal_n, int mw_n)
{
    numOfHeal = heal_n;
    numOfMW = mw_n;
}
// get the number of heal
int container::nOfHeal()
{
    return numOfHeal;
}
// get the number of magic water
int container::nOfMW()
{
    return numOfMW;
}
// display the items;
void container::display()
{
    cout << "Your bag contains: " << endl;
    cout << "Heal(HP+100): " << numOfHeal << endl;
    cout << "Magic Water (MP+80): " << numOfMW << endl;
}
//use heal
bool container::useHeal()
{
    numOfHeal--;
        return 1;       // use heal successfully
}
//use magic water
bool container::useMW()
{
    numOfMW--;
    return 1;       // use magic water successfully
} 
  • player.h
//=======================
//      player.h
//=======================
// The base class of player
// including the general properties and methods related to a character
#ifndef _PLAYER
#define _PLAYER
#include <iomanip>      // use for setting field width
#include <time.h>   // use for generating random factor
#include<string>
#include "container.h"
using namespace std;
enum job { sw, ar, mg };    /* define 3 jobs by enumerate type
                                sword man, archer, mage */
class player
{
    friend void showinfo(player &p1, player &p2);
    friend class swordsman;
    friend class archer;
    friend class mage;
protected:
    int HP, HPmax, MP, MPmax, AP, DP, speed, EXP, LV;
    // General properties of all characters
    string name;    // character name
    job role;       /* character's job, one of swordman, archer and mage,
                    as defined by the enumerate type */
    container bag;  // character's inventory
public:
    virtual bool attack(player &p) = 0; // normal attack
    virtual bool specialatt(player &p) = 0; //special attack
    virtual void isLevelUp() = 0;           // level up judgement
                                            /* Attention!
                                            These three methods are called "Pure virtual functions".
                                            They have only declaration, but no definition.
                                            The class with pure virtual functions are called "Abstract class", which can only be used to inherited, but not to constructor objects.
                                            The detailed definition of these pure virtual functions will be given in subclasses. */
    void reFill();      // character's HP and MP resume
    bool death();       // report whether character is dead
    void isDead();      // check whether character is dead
    bool useHeal();     // consume heal, irrelevant to job
    bool useMW();       // consume magic water, irrelevant to job
    void transfer(player &p);   // possess opponent's items after victory
    void showRole();    // display character's job
private:
    bool playerdeath;           // whether character is dead, doesn't need to be accessed or inherited
};
#endif 
  • player.cpp
//=======================
//      player.cpp
//=======================
#include<iostream>
#include"player.h"
using namespace std;
// character's HP and MP resume
void player::reFill()
{
    HP = HPmax;     // HP and MP fully recovered
    MP = MPmax;
}
// report whether character is dead
bool player::death()
{
    return playerdeath;
}
// check whether character is dead
void player::isDead()
{
    if (HP <= 0)        // HP less than 0, character is dead
    {
        cout << name << " is Dead." << endl;
        system("pause");
        playerdeath = 1;    // give the label of death value 1
    }
}
// consume heal, irrelevant to job
bool player::useHeal()
{
    if (bag.nOfHeal()>0)
    {
        HP = HP + 100;
        if (HP>HPmax)       // HP cannot be larger than maximum value
            HP = HPmax;     // so assign it to HPmax, if necessary
        cout << name << " used Heal, HP increased by 100." << endl;
        bag.useHeal();      // use heal
        system("pause");
        return 1;   // usage of heal succeed
    }
    else                // If no more heal in bag, cannot use
    {
        cout << "Sorry, you don't have heal to use." << endl;
        system("pause");
        return 0;   // usage of heal failed
    }
}
// consume magic water, irrelevant to job
bool player::useMW()
{
    if (bag.nOfMW()>0)
    {
        MP = MP + 100;
        if (MP>MPmax)
            MP = MPmax;
        cout << name << " used Magic Water, MP increased by 100." << endl;
        bag.useMW();
        system("pause");
        return 1;   // usage of magic water succeed
    }
    else
    {
        cout << "Sorry, you don't have magic water to use." << endl;
        system("pause");
        return 0;   // usage of magic water failed
    }
}
// possess opponent's items after victory
void player::transfer(player &p)
{
    cout << name << " got" << p.bag.nOfHeal() << " Heal, and " << p.bag.nOfMW() << " Magic Water." << endl;
    system("pause");
    bag.set(bag.nOfHeal() + p.bag.nOfHeal(), bag.nOfMW() + p.bag.nOfMW());
        // set the character's bag, get opponent's items
}
// display character's job
void player::showRole()
{
    switch (role)
    {
    case sw:
        cout << "Swordsman";
        break;
    case ar:
        cout << "Archer";
        break;
    case mg:
        cout << "Mage";
        break;
    default:
        break;
    }
}
// display character's job
void showinfo(player &p1,player &p2)
{
    system("cls");
    cout << "##############################################################" << endl;
    cout << "# Player" << setw(10) << p1.name << "   LV. " << setw(3) << p1.LV
        << "  # Opponent" << setw(10) << p2.name << "   LV. " << setw(3) << p2.LV << " #" << endl;
    cout << "# HP " << setw(3) << (p1.HP <= 999 ? p1.HP : 999) << '/' << setw(3) << (p1.HPmax <= 999 ? p1.HPmax : 999)
        << " | MP " << setw(3) << (p1.MP <= 999 ? p1.MP : 999) << '/' << setw(3) << (p1.MPmax <= 999 ? p1.MPmax : 999)
        << "     # HP " << setw(3) << (p2.HP <= 999 ? p2.HP : 999) << '/' << setw(3) << (p2.HPmax <= 999 ? p2.HPmax : 999)
        << " | MP " << setw(3) << (p2.MP <= 999 ? p2.MP : 999) << '/' << setw(3) << (p2.MPmax <= 999 ? p2.MPmax : 999) << "      #" << endl;
    cout << "# AP " << setw(3) << (p1.AP <= 999 ? p1.AP : 999)
        << " | DP " << setw(3) << (p1.DP <= 999 ? p1.DP : 999)
        << " | speed " << setw(3) << (p1.speed <= 999 ? p1.speed : 999)
        << " # AP " << setw(3) << (p2.AP <= 999 ? p2.AP : 999)
        << " | DP " << setw(3) << (p2.DP <= 999 ? p2.DP : 999)
        << " | speed " << setw(3) << (p2.speed <= 999 ? p2.speed : 999) << "  #" << endl;
    cout << "# EXP" << setw(7) << p1.EXP << " Job: " << setw(7);
    p1.showRole();
    cout << "   # EXP" << setw(7) << p2.EXP << " Job: " << setw(7);
    p2.showRole();
    cout << "    #" << endl;
    cout << "--------------------------------------------------------------" << endl;
    p1.bag.display();
    cout << "##############################################################" << endl;
} 
  • swordsman.h
//=======================
//      swordsman.h
//=======================
// Derived from base class player
// For the job Swordsman
#include "player.h"
#include<string>
using namespace std;
class swordsman : public player // subclass swordsman publicly inherited from base player
{
public:
    swordsman(int lv_in = 1, string name_in = "Not Given");
    // constructor with default level of 1 and name of "Not given"
    void isLevelUp();
    bool attack(player &p);
    bool specialatt(player &p);
    /* These three are derived from the pure virtual functions of base class
    The definition of them will be given in this subclass. */
    void AI(player &p);             // Computer opponent
};
  • swordsman.cpp
//=======================
//      swordsman.cpp
//=======================
#include"swordsman.h"
#include<iostream>
using namespace std;
// constructor. default values don't need to be repeated here
swordsman::swordsman(int lv_in, string name_in)
{
    role = sw;  // enumerate type of job
    LV = lv_in;
    name = name_in;
    // Initialising the character's properties, based on his level
    HPmax = 150 + 8 * (LV - 1);     // HP increases 8 point2 per level
    HP = HPmax;
    MPmax = 75 + 2 * (LV - 1);      // MP increases 2 points per level
    MP = MPmax;
    AP = 25 + 4 * (LV - 1);         // AP increases 4 points per level
    DP = 25 + 4 * (LV - 1);         // DP increases 4 points per level
    speed = 25 + 2 * (LV - 1);      // speed increases 2 points per level
    playerdeath = 0;
    EXP = LV * LV * 75;
    bag.set(lv_in, lv_in);
}
void swordsman::isLevelUp()
{
    if (EXP >= LV * LV * 75)
    {
        LV++;
        AP += 4;
        DP += 4;
        HPmax += 8;
        MPmax += 2;
        speed += 2;
        cout << name << " Level UP!" << endl;
        cout << "HP improved 8 points to " << HPmax << endl;
        cout << "MP improved 2 points to " << MPmax << endl;
        cout << "Speed improved 2 points to " << speed << endl;
        cout << "AP improved 4 points to " << AP << endl;
        cout << "DP improved 5 points to " << DP << endl;
        system("pause");
        isLevelUp();    // recursively call this function, so the character can level up multiple times if got enough exp
    }
}
bool swordsman::attack(player &p)
{
    double HPtemp = 0;      // opponent's HP decrement
    double EXPtemp = 0;     // player obtained exp
    double hit = 1;         // attach factor, probably give critical attack
    srand((unsigned)time(NULL));        // generating random seed based on system time
                                        // If speed greater than opponent, you have some possibility to do double attack
    if ((speed>p.speed) && (rand() % 100<(speed - p.speed)))        // rand()%100 means generates a number no greater than 100
    {
        HPtemp = (int)((1.0*AP / p.DP)*AP * 5 / (rand() % 4 + 10));     // opponent's HP decrement calculated based their AP/DP, and uncertain chance
        cout << name << "'s quick strike hit " << p.name << ", " << p.name << "'s HP decreased " << HPtemp << endl;
        p.HP = int(p.HP - HPtemp);
        EXPtemp = (int)(HPtemp*1.2);
    }
    // If speed smaller than opponent, the opponent has possibility to evade
    if ((speed<p.speed) && (rand() % 50<1))
    {
        cout << name << "'s attack has been evaded by " << p.name << endl;
        system("pause");
        return 1;
    }
    // 10% chance give critical attack
    if (rand() % 100 <= 10)
    {
        hit = 1.5;
        cout << "Critical attack: ";
    }
    // Normal attack
    HPtemp = (int)((1.0*AP / p.DP)*AP * 5 / (rand() % 4 + 10));
    cout << name << " uses bash, " << p.name << "'s HP decreases " << HPtemp << endl;
    EXPtemp = (int)(EXPtemp + HPtemp * 1.2);
    p.HP = (int)(p.HP - HPtemp);
    cout << name << " obtained " << EXPtemp << " experience." << endl;
    EXP = (int)(EXP + EXPtemp);
    system("pause");
    return 1;       // Attack success
}
bool swordsman::specialatt(player &p)
{
    if (MP<40)
    {
        cout << "You don't have enough magic points!" << endl;
        system("pause");
        return 0;       // Attack failed
    }
    else
    {
        MP -= 40;           // consume 40 MP to do special attack

                            //10% chance opponent evades
        if (rand() % 100 <= 10)
        {
            cout << name << "'s leap attack has been evaded by " << p.name << endl;
            system("pause");
            return 1;
        }

        double HPtemp = 0;
        double EXPtemp = 0;
        //double hit=1;         
        //srand(time(NULL));        
        HPtemp = (int)(AP*1.2 + 20);        // not related to opponent's DP
        EXPtemp = (int)(HPtemp*1.5);        // special attack provides more experience
        cout << name << " uses leap attack, " << p.name << "'s HP decreases " << HPtemp << endl;
        cout << name << " obtained " << EXPtemp << " experience." << endl;
        p.HP = (int)(p.HP - HPtemp);
        EXP = (int)(EXP + EXPtemp);
        system("pause");
    }
    return 1;   // special attack succeed
}
// Computer opponent
void swordsman::AI(player &p)
{
    if ((HP<(int)((1.0*p.AP / DP)*p.AP*1.5)) && (HP + 100 <= 1.1*HPmax) && (bag.nOfHeal()>0) && (HP>(int)((1.0*p.AP / DP)*p.AP*0.5)))
        // AI's HP cannot sustain 3 rounds && not too lavish && still has heal && won't be killed in next round
    {
        useHeal();
    }
    else
    {
        if (MP >= 40 && HP>0.5*HPmax && rand() % 100 <= 30)
            // AI has enough MP, it has 30% to make special attack
        {
            specialatt(p);
            p.isDead();     // check whether player is dead
        }
        else
        {
            if (MP<40 && HP>0.5*HPmax && bag.nOfMW())
                // Not enough MP && HP is safe && still has magic water
            {
                useMW();
            }
            else
            {
                attack(p);  // normal attack
                p.isDead();
            }
        }
    }
}
  • mage.h
#pragma once
#include "player.h"
#include<string>
class mage :
    public player
{
public:
    mage(int lv_in = 1, string name_in = "Not Given");
    void isLevelUp();
    bool attack(player &p);
    bool specialatt(player &p);
    void AI(player &p);
    ~mage();
};
  • mage.cpp
#include "mage.h"
#include<iostream>
mage::mage(int lv_in,string name_in)
{
    role = mg;  // enumerate type of job
    LV = lv_in;
    name = name_in;
    // Initialising the character's properties, based on his level
    HPmax = 100 + 5 * (LV - 1);     // HP increases 5 point2 per level
    HP = HPmax;
    MPmax = 130 + 5 * (LV - 1);     // MP increases 5 points per level
    MP = MPmax;
    AP = 45 + 8 * (LV - 1);         // AP increases 8 points per level
    DP = 10 + 2 * (LV - 1);         // DP increases 2 points per level
    speed = 15 + 1 * (LV - 1);      // speed increases 1 points per level
    playerdeath = 0;
    EXP = LV * LV * 75;
    bag.set(lv_in, lv_in);
}
void mage::isLevelUp() {
    if (EXP >= LV * LV * 75)
    {
        LV++;
        AP += 8;
        DP += 2;
        HPmax += 5;
        MPmax += 5;
        speed += 1;
        cout << name << " Level UP!" << endl;
        cout << "HP improved 5 points to " << HPmax << endl;
        cout << "MP improved 5 points to " << MPmax << endl;
        cout << "Speed improved 1 points to " << speed << endl;
        cout << "AP improved 8 points to " << AP << endl;
        cout << "DP improved 2 points to " << DP << endl;
        system("pause");
        isLevelUp();    // recursively call this function, so the character can level up multiple times if got enough exp
    }
}
bool mage::attack(player &p) {
    double HPtemp = 0;      // opponent's HP decrement
    double EXPtemp = 0;     // player obtained exp
    double hit = 1;         // attach factor, probably give critical attack
    srand((unsigned)time(NULL));        // generating random seed based on system time

                                        // If speed greater than opponent, you have some possibility to do double attack
    if ((speed>p.speed) && (rand() % 100<(speed - p.speed)))        // rand()%100 means generates a number no greater than 100
    {
        HPtemp = (int)((1.0*AP / p.DP)*AP * 5 / (rand() % 4 + 10));     // opponent's HP decrement calculated based their AP/DP, and uncertain chance
        cout << name << "'s quick strike hit " << p.name << ", " << p.name << "'s HP decreased " << HPtemp << endl;
        p.HP = int(p.HP - HPtemp);
        EXPtemp = (int)(HPtemp*1.2);
    }
    // If speed smaller than opponent, the opponent has possibility to evade
    if ((speed < p.speed) && (rand() % 50 < 1))
    {
        cout << name << "'s attack has been evaded by " << p.name << endl;
        system("pause");
        return 1;
    }
    // 10% chance give critical attack
    if (rand() % 100 <= 10)
    {
        hit = 1.5;
        cout << "Critical attack: ";
    }
    // Normal attack
    HPtemp = (int)((1.0*AP / p.DP)*AP * 5 / (rand() % 4 + 10));
    cout << name << " uses bash, " << p.name << "'s HP decreases " << HPtemp << endl;
    EXPtemp = (int)(EXPtemp + HPtemp * 1.2);
    p.HP = (int)(p.HP - HPtemp);
    cout << name << " obtained " << EXPtemp << " experience." << endl;
    EXP = (int)(EXP + EXPtemp);
    system("pause");
    return 1;       // Attack success
}
bool mage::specialatt(player &p) {
    if (MP<40)
    {
        cout << "You don't have enough magic points!" << endl;
        system("pause");
        return 0;       // Attack failed
    }
    else
    {
        MP -= 40;           // consume 40 MP to do special attack

                            //10% chance opponent evades
        if (rand() % 100 <= 10)
        {
            cout << name << "'s leap attack has been evaded by " << p.name << endl;
            system("pause");
            return 1;
        }
        double HPtemp = 0;
        double EXPtemp = 0;
        //double hit=1;         
        //srand(time(NULL));        
        HPtemp = (int)(AP*1.2 + 20);        // not related to opponent's DP
        EXPtemp = (int)(HPtemp*1.5);        // special attack provides more experience
        cout << name << " uses leap attack, " << p.name << "'s HP decreases " << HPtemp << endl;
        cout << name << " obtained " << EXPtemp << " experience." << endl;
        p.HP = (int)(p.HP - HPtemp);
        EXP = (int)(EXP + EXPtemp);
        system("pause");
    }
    return 1;   // special attack succeed
}
void mage::AI(player &p) {
    if ((HP<(int)((1.0*p.AP / DP)*p.AP*1.5)) && (HP + 100 <= 1.1*HPmax) && (bag.nOfHeal()>0) && (HP>(int)((1.0*p.AP / DP)*p.AP*0.5)))
        // AI's HP cannot sustain 3 rounds && not too lavish && still has heal && won't be killed in next round
    {
        useHeal();
    }
    else
    {
        if (MP >= 40 && HP>0.5*HPmax && rand() % 100 <= 30)
            // AI has enough MP, it has 30% to make special attack
        {
            specialatt(p);
            p.isDead();     // check whether player is dead
        }
        else
        {
            if (MP<40 && HP>0.5*HPmax && bag.nOfMW())
                // Not enough MP && HP is safe && still has magic water
            {
                useMW();
            }
            else
            {
                attack(p);  // normal attack
                p.isDead();
            }
        }
    }
}
mage::~mage()
{
}
  • archer.h
#pragma once
#include"player.h"
#include<string>
using namespace std;
class archer:public player
{
public:
    archer(int lv_in = 1, string name_in = "Not Given");
    void isLevelUp();
    bool attack(player &p);
    bool specialatt(player &p);
    void AI(player &p);
    ~archer();
};
  • archer.cpp
#include "archer.h"
#include<iostream>
using namespace std;
archer::archer(int lv_in,string name_in)
{
    role = ar;  // enumerate type of job
    LV = lv_in;
    name = name_in;
    // Initialising the character's properties, based on his level
    HPmax = 130 + 6 * (LV - 1);     // HP increases 6 point2 per level
    HP = HPmax;
    MPmax = 80 + 4 * (LV - 1);      // MP increases 4 points per level
    MP = MPmax;
    AP = 35 + 6 * (LV - 1);         // AP increases 6 points per level
    DP = 20 + 2 * (LV - 1);         // DP increases 2 points per level
    speed = 40 + 5 * (LV - 1);      // speed increases 5 points per level
    playerdeath = 0;
    EXP = LV * LV * 75;
    bag.set(lv_in, lv_in);
}
void archer::isLevelUp() {
    if (EXP >= LV * LV * 75)
    {
        LV++;
        AP += 6;
        DP += 2;
        HPmax += 6;
        MPmax += 4;
        speed += 5;
        cout << name << " Level UP!" << endl;
        cout << "HP improved 6 points to " << HPmax << endl;
        cout << "MP improved 4 points to " << MPmax << endl;
        cout << "Speed improved 5 points to " << speed << endl;
        cout << "AP improved 6 points to " << AP << endl;
        cout << "DP improved 2 points to " << DP << endl;
        system("pause");
        isLevelUp();    // recursively call this function, so the character can level up multiple times if got enough exp
    }
}
bool archer::attack(player &p) {
    double HPtemp = 0;      // opponent's HP decrement
    double EXPtemp = 0;     // player obtained exp
    double hit = 1;         // attach factor, probably give critical attack
    srand((unsigned)time(NULL));        // generating random seed based on system time
                                        // If speed greater than opponent, you have some possibility to do double attack
    if ((speed>p.speed) && (rand() % 100<(speed - p.speed)))        // rand()%100 means generates a number no greater than 100
    {
        HPtemp = (int)((1.0*AP / p.DP)*AP * 5 / (rand() % 4 + 10));     // opponent's HP decrement calculated based their AP/DP, and uncertain chance
        cout << name << "'s quick strike hit " << p.name << ", " << p.name << "'s HP decreased " << HPtemp << endl;
        p.HP = int(p.HP - HPtemp);
        EXPtemp = (int)(HPtemp*1.2);
    }
    // If speed smaller than opponent, the opponent has possibility to evade
    if ((speed<p.speed) && (rand() % 50<1))
    {
        cout << name << "'s attack has been evaded by " << p.name << endl;
        system("pause");
        return 1;
    }
    // 10% chance give critical attack
    if (rand() % 100 <= 10)
    {
        hit = 1.5;
        cout << "Critical attack: ";
    }
    // Normal attack
    HPtemp = (int)((1.0*AP / p.DP)*AP * 5 / (rand() % 4 + 10));
    cout << name << " uses bash, " << p.name << "'s HP decreases " << HPtemp << endl;
    EXPtemp = (int)(EXPtemp + HPtemp * 1.2);
    p.HP = (int)(p.HP - HPtemp);
    cout << name << " obtained " << EXPtemp << " experience." << endl;
    EXP = (int)(EXP + EXPtemp);
    system("pause");
    return 1;       // Attack success
}
bool archer::specialatt(player &p) {
    if (MP<40)
    {
        cout << "You don't have enough magic points!" << endl;
        system("pause");
        return 0;       // Attack failed
    }
    else
    {
        MP -= 40;           // consume 40 MP to do special attack

                            //10% chance opponent evades
        if (rand() % 100 <= 10)
        {
            cout << name << "'s leap attack has been evaded by " << p.name << endl;
            system("pause");
            return 1;
        }
        double HPtemp = 0;
        double EXPtemp = 0;
        //double hit=1;         
        //srand(time(NULL));        
        HPtemp = (int)(AP*1.2 + 20);        // not related to opponent's DP
        EXPtemp = (int)(HPtemp*1.5);        // special attack provides more experience
        cout << name << " uses leap attack, " << p.name << "'s HP decreases " << HPtemp << endl;
        cout << name << " obtained " << EXPtemp << " experience." << endl;
        p.HP = (int)(p.HP - HPtemp);
        EXP = (int)(EXP + EXPtemp);
        system("pause");
    }
    return 1;   // special attack succeed
}
void archer::AI(player &p) {
    if ((HP<(int)((1.0*p.AP / DP)*p.AP*1.5)) && (HP + 100 <= 1.1*HPmax) && (bag.nOfHeal()>0) && (HP>(int)((1.0*p.AP / DP)*p.AP*0.5)))
        // AI's HP cannot sustain 3 rounds && not too lavish && still has heal && won't be killed in next round
    {
        useHeal();
    }
    else
    {
        if (MP >= 40 && HP>0.5*HPmax && rand() % 100 <= 30)
            // AI has enough MP, it has 30% to make special attack
        {
            specialatt(p);
            p.isDead();     // check whether player is dead
        }
        else
        {
            if (MP<40 && HP>0.5*HPmax && bag.nOfMW())
                // Not enough MP && HP is safe && still has magic water
            {
                useMW();
            }
            else
            {
                attack(p);  // normal attack
                p.isDead();
            }
        }
    }
}
archer::~archer()
{
}
  • main.cpp
//=======================
//      main.cpp
//=======================
// main function for the RPG style game
#include <iostream>
#include <string>
using namespace std;
#include "swordsman.h"
#include"archer.h"
#include"mage.h"
int main()
{
    string tempName;
    bool success = 0;       //flag for storing whether operation is successful
    cout << "Please input player's name: ";
    cin >> tempName;        // get player's name from keyboard input
    player *human=NULL;     // use pointer of base class, convenience for polymorphism
    int tempJob;        // temp choice for job selection
    do
    {
        cout << "Please choose a job: 1 Swordsman, 2 Archer, 3 Mage" << endl;
        cin >> tempJob;
        system("cls");      // clear the screen
        switch (tempJob)
        {
        case 1:
            human = new swordsman(1, tempName); // create the character with user inputted name and job
            success = 1;        // operation succeed
            break;
        case 2:
            human = new archer(1, tempName);
            success = 1;
            break;
        case 3:
            human = new mage(1, tempName);
            success = 1;
            break;
        default:
            break;              // In this case, success=0, character creation failed
        }
    } while (success != 1);     // so the loop will ask user to re-create a character
    int tempCom;            // temp command inputted by user
    int nOpp = 0;               // the Nth opponent
    for (int i = 1; nOpp<5; i += 2) // i is opponent's level
    {
        nOpp++;
        if (rand() % 100 <= 33) {
            swordsman enemy(i, "ai_swordsman");
            system("cls");
            cout << "STAGE" << nOpp << endl;
            cout << "Your opponent, a Level " << i << " Swordsman." << endl;
            system("pause");
            //Initialise an opponent, level i, name "Junior"
            human->reFill();                // get HP/MP refill before start fight
            while (!human->death() && !enemy.death())   // no died
            {
                success = 0;
                while (success != 1)
                {
                    showinfo(*human, enemy);                // show fighter's information
                    cout << "Please give command: " << endl;
                    cout << "1 Attack; 2 Special Attack; 3 Use Heal; 4 Use Magic Water; 0 Exit Game" << endl;
                    cin >> tempCom;
                    switch (tempCom)
                    {
                    case 0:
                        cout << "Are you sure to exit? Y/N" << endl;
                        char temp;
                        cin >> temp;
                        if (temp == 'Y' || temp == 'y')
                            return 0;
                        else
                            break;
                    case 1:
                        success = human->attack(enemy);
                        human->isLevelUp();
                        enemy.isDead();
                        break;
                    case 2:
                        success = human->specialatt(enemy);
                        human->isLevelUp();
                        enemy.isDead();
                        break;
                    case 3:
                        success = human->useHeal();
                        break;
                    case 4:
                        success = human->useMW();
                        break;
                    default:
                        break;
                    }
                }
                if (!enemy.death())     // If AI still alive
                    enemy.AI(*human);
                else                            // AI died
                {
                    cout << "YOU WIN" << endl;
                    human->transfer(enemy);     // player got all AI's items
                }
                if (human->death())
                {
                    system("cls");
                    cout << endl << setw(50) << "GAME OVER" << endl;
                    delete human;       // player is dead, program is getting to its end, what should we do here?
                    system("pause");
                    return 0;
                }
            }
        }
        else if ((rand() % 100 <= 66)&&(rand()%100>33)) {
            archer enemy(i, "ai_archer");
            system("cls");
            cout << "STAGE" << nOpp << endl;
            cout << "Your opponent, a Level " << i << " Archer." << endl;
            system("pause");
            //Initialise an opponent, level i, name "Junior"
            human->reFill();                // get HP/MP refill before start fight
            while (!human->death() && !enemy.death())   // no died
            {
                success = 0;
                while (success != 1)
                {
                    showinfo(*human, enemy);                // show fighter's information
                    cout << "Please give command: " << endl;
                    cout << "1 Attack; 2 Special Attack; 3 Use Heal; 4 Use Magic Water; 0 Exit Game" << endl;
                    cin >> tempCom;
                    switch (tempCom)
                    {
                    case 0:
                        cout << "Are you sure to exit? Y/N" << endl;
                        char temp;
                        cin >> temp;
                        if (temp == 'Y' || temp == 'y')
                            return 0;
                        else
                            break;
                    case 1:
                        success = human->attack(enemy);
                        human->isLevelUp();
                        enemy.isDead();
                        break;
                    case 2:
                        success = human->specialatt(enemy);
                        human->isLevelUp();
                        enemy.isDead();
                        break;
                    case 3:
                        success = human->useHeal();
                        break;
                    case 4:
                        success = human->useMW();
                        break;
                    default:
                        break;
                    }
                }
                if (!enemy.death())     // If AI still alive
                    enemy.AI(*human);
                else                            // AI died
                {
                    cout << "YOU WIN" << endl;
                    human->transfer(enemy);     // player got all AI's items
                }
                if (human->death())
                {
                    system("cls");
                    cout << endl << setw(50) << "GAME OVER" << endl;
                    delete human;       // player is dead, program is getting to its end, what should we do here?
                    system("pause");
                    return 0;
                }
            }
        }
        else{
            mage enemy(i, "ai_mage");
            system("cls");
            cout << "STAGE" << nOpp << endl;
            cout << "Your opponent, a Level " << i << " Mage." << endl;
            system("pause");
            //Initialise an opponent, level i, name "Junior"
            human->reFill();                // get HP/MP refill before start fight
            while (!human->death() && !enemy.death())   // no died
            {
                success = 0;
                while (success != 1)
                {
                    showinfo(*human, enemy);                // show fighter's information
                    cout << "Please give command: " << endl;
                    cout << "1 Attack; 2 Special Attack; 3 Use Heal; 4 Use Magic Water; 0 Exit Game" << endl;
                    cin >> tempCom;
                    switch (tempCom)
                    {
                    case 0:
                        cout << "Are you sure to exit? Y/N" << endl;
                        char temp;
                        cin >> temp;
                        if (temp == 'Y' || temp == 'y')
                            return 0;
                        else
                            break;
                    case 1:
                        success = human->attack(enemy);
                        human->isLevelUp();
                        enemy.isDead();
                        break;
                    case 2:
                        success = human->specialatt(enemy);
                        human->isLevelUp();
                        enemy.isDead();
                        break;
                    case 3:
                        success = human->useHeal();
                        break;
                    case 4:
                        success = human->useMW();
                        break;
                    default:
                        break;
                    }
                }
                if (!enemy.death())     // If AI still alive
                    enemy.AI(*human);
                else                            // AI died
                {
                    cout << "YOU WIN" << endl;
                    human->transfer(enemy);     // player got all AI's items
                }
                if (human->death())
                {
                    system("cls");
                    cout << endl << setw(50) << "GAME OVER" << endl;
                    delete human;       // player is dead, program is getting to its end, what should we do here?
                    system("pause");
                    return 0;
                }
            }
        }
    }
    delete human;           // You win, program is getting to its end, what should we do here?
        system("cls");
    cout << "Congratulations! You defeated all opponents!!" << endl;
    system("pause");
    return 0;
}

转载于:https://www.cnblogs.com/flyingbrid-nest/p/9135236.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

实验六 的相关文章

  • python网络协议

    一 互联网的本质 咱们先不说互联网是如何通信的 发送数据 xff0c 文件等 xff0c 先用一个经典的例子 xff0c 给大家说明什么是互联网通信 现在追溯到八九十年代 xff0c 当时电话刚刚兴起 xff0c 还没有手机的概念 xff0
  • 通过css 改变通过img标签引入的svg颜色

    前言 修改svg颜色 xff0c 一般直接修改文件的svg的fill属性就可以了 xff0c 可以直接改svg属性 xff0c 也可以通过css修改 xff0c 但是前端一般都是通过img标签直接引入的svg图片 xff0c 这样不管是从后
  • Linux环境下vs code中Markdown与PlantUML联合工作

    PlantUML是一个可以让你快速编写UML图的组件 在线服务器 https www plantuml com plantuml uml SyfFKj2rKt3CoKnELR1Io4ZDoSa70000 Markdown是一种轻量级标记语言
  • FPGA到底是什么

    做FPGA设计这么久 xff0c 每次给别人介绍的时候 xff0c 总是感觉讲的不够深刻 xff0c 惭愧惭愧惭愧 这次 xff0c 我就FPGA的硬件属性来展开 xff0c 简单写写 xff0c 与大家分享 我的许多朋友都是经验丰富的算法
  • 一个玩游戏的失足青年,转行做游戏开发到教育的挣扎过程

    14年的IT从业经历 xff0c 中专毕业后在小镇上开过网吧 在网吧一年多的时间里 xff0c 天天陪人玩游戏 xff0c 后来去读了一个三流计算机专业 xff0c 毕业后转做软件开发 xff0c 最近五年转入游戏开发行业 xff01 从网
  • 电路设计基础--MOS管驱动直流电机电路,看懂芯片手册

    本例以驱动继电器为例 xff0c 来讲述相关电路设计 xff0c MOS管选型 xff0c 以及看懂芯片手册 驱动电路如下图 D1作用是泄放继电器的反向电动势 继电器参数 24V继电器 电大负载25A 250VAC xff0c 线圈电阻64
  • linux下 /usr/bin/ld: 找不到 -ldhnetsdk的解决方法

    linux下使用Qt编译程序的时候 xff0c 安装了程序自带的链接库之后 xff0c 仍然上报这个错误 xff0c 发现系统上报这个错误 xff1a usr bin ld 找不到 ldhnetsdk 经过仔细的定位 xff0c 终于解决了
  • 无人机--飞控科普

    无人机是无人驾驶飞机的简称 xff08 Unmanned Aerial Vehicle xff0c UAV xff09 xff0c 是利用无线电遥控设备和自备的程序控制装置的不载人飞机 xff0c 包括无人直升机 固定翼机 多旋翼飞行器 无
  • 远程桌面使用双屏或多屏

    选项 显示 将所有监视器用于显示 查了半天居然没有靠谱答案 xff0c 自己动手发现 转载于 https www cnblogs com phoenix p 4294103 html
  • 问题记录:未设置为接受端口“文件和打印机共享(SMB)”上的连接

    解决办法 xff1a 网络 xff08 右击 xff09 属性 本地连接 xff08 右击 xff09 属性 此连接使用下列选项 Microsoft网络的文和打印共享 xff08 打上勾 xff09 转载于 https www cnblog
  • arduino 语音音箱 :语音控制、MP3播放、报时、回复温湿度情况

    arduino 语音音箱 xff1a 语音控制 MP3播放 报时 回复温湿度情况 效果图 线路图 包装后的效果 功能 需要材料 arduino板MP3播放模块及喇叭时钟模块温湿度模块语音识别模块面包板及其他线材 电阻TF卡 xff08 用于
  • 通过多张网卡发送UDP多播(组播)数据

    在具有多个网卡的机器上 xff0c 如果想要从每个网卡发送UDP数据 xff0c 一般的做法是 xff1a 针对每张网卡的每个IP都绑定一个SOCKET xff0c 然后发送的时候针对每个SOCKET都发送一次 但是如果你要发送多播数据 x
  • 常见的HTTP状态码

    本内容摘抄自RESTful WebServices 中文译本附录B 39 42种常见的HTTP响应代码 39 原文作者 xff1a Leonard Ricbardson amp Sam Ruby 翻译 xff1a 徐涵 李红军 胡伟 1 三
  • ps快速切图

    妈呀 xff0c 不得不感慨一下 xff0c 切了这么久的图 xff0c 竟然不知道有个切图工具这么好用 以前我的切图流程 xff1a 拿到ui设计好的psd文件 61 61 gt 拉基准线 61 61 gt 切片工具切图 61 61 gt
  • MongoDB v4.0 命令

    MongoDB v4 0 命令 官方文档 gt 点这里 lt 操作系统库 操作管理员库 use admin 鉴权 db auth 34 root 34 34 admin 34 用户查看 格式美化 db system users find p
  • 查看端口是否可访问(防火墙拦截处理)

    telnet ip 端口 例如 xff1a telnet 10 20 113 15 8080 出现 Escape character is 表示连接 xff0c 没有被防火墙拦截 转载于 https www cnblogs com kdx
  • ESP32-CAM上手

    硬件 ESP32 CAM摄像头开发板 安信可科技 ESP32 CAM摄像头开发板 https item taobao com item htm spm 61 a1z09 2 0 0 67002e8dvbTVMF amp id 61 6159
  • 面试时如何做好5分钟自我介绍?

    有简历 xff0c 为何还要自我介绍 xff1f 一个常规的面试 xff0c 寒暄之后面试官提出的第一个问题几乎千篇一律 xff1a 请您简单地做一下自我介绍 有些被面试者都会问 xff1a 简历中情况已经写得很清楚了 xff0c 这是否多
  • windows查看当前python的版本

    1 Ctrl 43 R打开控制台 输入python之后回车 转载于 https www cnblogs com CK85 p 10243904 html
  • 利用MATLAB绘制置信区域

    lt MATLAB小技巧之二十四 xff1a 利用MATLAB绘制置信区域 gt 统计中经常会遇到求置信区间 置信区域 xff08 如置信椭圆 置信椭球 xff09 等 xff0c 有时候需要把置信区域画出来 xff0c 这样看起看更为直观

随机推荐

  • 关于latex编译中文不显示问题的解决方法。

    我的编译环境是texlive2018 43 texstudio 配置如图 默认编码格式为utf8 直接上代码 documentclass article usepackage xeCJK documentclass UTF8 ctexart
  • 最新百度 阿里 华为 腾讯 谷歌面试笔试题及解析 (转)

    原文地址 xff1a http m blog csdn net blog panfengyun12345 12618453 8月15日 xff0c 百度2道面试题 xff1a 1 来自 编程之美 的概率题 xff1a 一个桶里面有白球 黑球
  • 归并排序——C语言

    归并排序 归并排序 xff08 MERGE SORT xff09 是建立在归并操作上的一种有效的排序算法 该算法采用经典的分治 xff08 divide and conquer xff09 策略 xff08 分治法将问题分 divide 成
  • Linux设备驱动程序学习(19)-USB 驱动程序(四)

    编写 USB 驱动程序 xff08 本部分的一些示例源码来自drivers usb usb skeleton c xff0c 它是Linux内核为我们提供的最基础的USB驱动程序 xff0c USB骨架程序 xff09 驱动程序把驱动对象注
  • Linux----面试

    1 tcp和udp的区别 TCP xff1a 是面向连接的流传输控制协议 xff0c 具有高可靠性 xff0c 确保传输数据的正确性 xff0c 有验证重发机制 xff0c 因此不会出现丢失或乱序 UDP xff1a 是无连接的数据报服务
  • ssh免密码登陆失败的原因

    今天因为需要在两台服务器上进行ssh免登陆 xff0c 所以安装网上的教程 xff0c ssh keygen t rsa xff0c 然后把相互的密钥加入到对方的authorized keys 问题是我们虽然这样做了 xff0c 却一直要密
  • ESP32-s2芯片esp32-s2-saola-1开发板 micropython的repl连接

    本文只是解决通过esp32 s2 saola 1开发板 自带microUSB 作为repl与micro python通信的问题 如果你对esp32 xff0c micropython不熟 xff0c 本文不适合你 如果你用的不是esp32
  • 机械臂模拟2.0

    机械臂模拟 void MobileCrane updateHopeLength int center x int center y int center z int armNodeNum int ropePitchNum int baseN
  • Qt获取时间戳作为图片名

    Qt获取时间戳作为图片名 保存图片 void SaveRealsenseImg QString picIndexName 61 dataSavePath picIndexName append 34 34 获取当前时间 QDateTime
  • [转&精]IO_STACK_LOCATION与IRP的一点笔记

    IO STACK LOCATION和IRP算是驱动中两个很基础的东西 xff0c 为了理解这两个东西 xff0c 找了一点资料 1 IRP可以看成是Win32窗口程序中的消息 xff08 Message xff09 xff0c DEVICE
  • wireshark抓包结果很多[TCP Retransmission]怎么办?

    有一同事问用wireshark抓包时发现很多 TCP Retransmission xff0c 这些包极大影响了自己真正想看的http数据包 xff0c 如下图 我拿到pcapng后首先看到这些包的来源ip都是固定的两个 xff0c 所以首
  • MATLAB神经网络训练结果各参数解释

    最上面的图形显示的是神经网络的结构图 xff0c 可知有一个隐层一个输出层 第二部分显示的是训练算法 xff0c 这里为学习率自适应的梯度下降BP算法 xff1b 误差指标为MSE 第三部分显示训练进度 xff1a Epoch xff1a
  • SQL语句统计个数大于一的记录

    1 主要是利用Having语句进行 xff0c 由于where不能与聚合函数一起使用 xff0c 所以用having SELECT MC COUNT MC AS SL FROM JSB GROUP BY MC HAVING COUNT MC
  • You must give at least one requirement to install (see "pip help install")

    语言 python why install 后面没有参数 xff0c 也就是说没有给想要安装的包 way pip install 后面要跟想要安装的包名 转载于 https www cnblogs com 2bjiujiu p 902966
  • VHDL乘除法及转换

    首先鄙视一下这个不智能的语言 1 要进行乘法与除法 xff0c 数据类型必须是signed 2 两个16位的数相乘 xff0c 结果必须是32位的 3 乘以2的n次幂的数可以直接乘 xff0c 之后截位也比较方便 xff0c xff08 其
  • C语言真正的编译过程

    说实话 xff0c 很多人做了很久的C C 43 43 也用了很多IDE xff0c 但是对于可执行程序的底层生成一片茫然 xff0c 这无疑是一种悲哀 xff0c 可以想象到大公司面试正好被问到这样的问题 xff0c 有多悲催不言而喻 x
  • Docker 删除&清理镜像

    文章首发自个人网站 xff1a https www exception site docker docker delete image 本文中 xff0c 您将学习 Docker 如何删除及清理镜像 xff1f 一 通过标签删除镜像 通过如
  • 解决:invalid application of `sizeof' to incomplete type `({anonymous})'错误

    这个错误的原因 xff1a sizeof不能用在extern变量 xff0c sizeof 的计算发生在代码编译 的时刻 extern 标注的符号 在链接的时刻解析 所以 sizeof 不知道 这个符号到底占用了多少空间 发生错误的程序是这
  • 自制吸锡带

    焊接qfp封装芯片的时候 xff0c 由于两个引脚间距过小 xff0c 常常会在引脚上留有焊锡 xff0c 这个时候就需要吸锡带 xff0c 但是一般情况下我们手边的设备并不齐全 xff0c 所以我们可以利用手边的工具自制 工具 xff1a
  • 实验六

    芯片派生 include lt iostream gt using namespace std class Base public void add int x int y cout lt lt x lt lt 34 43 34 lt lt