Hiển thị các bài đăng có nhãn Lập trình hướng đối tượng. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Lập trình hướng đối tượng. Hiển thị tất cả bài đăng
Ứng dụng lớp điểm ký tự xây dựng trò chơi bắn chữ

Ứng dụng lớp điểm ký tự xây dựng trò chơi bắn chữ


CDIEM.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace bt18
{
   class 
CDIEM
    
{
        private 
int x;
        private 
int y;
        public 
char c;

        public 
CDIEM()
        {
        }

        public 
CDIEM(int xxint yychar cc)
        {
            
xx;
            
yy;
            
cc;
        }

        public 
bool KiemTraX(int xx)
        {
            if (
xx <= || xx >= Console.WindowWidth)
            {
                return 
false;
            }
            return 
true;
        }
        public 
bool KiemTraY(int yy)
        {
            if (
yy <= || yy >= Console.WindowHeight)
            {
                return 
false;
            }
            return 
true;
        }

        public 
void DichPhai(int k)
        {
            
+= k;
        }
        public 
void DichTrai(int k)
        {
            
-= k;
        }
        public 
void DichLen(int k)
        {
            
-= k;
        }
        public 
void DichXuong(int k)
        {
            
+= k;
        }

        public 
void Xuat()
        {
            
Console.SetCursorPosition(xy);
            
Console.Write(c);
        }

        public 
void Xoa()
        {
            
Console.Clear();
        }

        public 
float KhoangCach(CDIEM M)
        {
            return 
0;
        }
        public 
int KhoangCachX()
        {
            return 
x;
        }
        public 
int KhoangCachY()
        {
            return 
y;
        }

    }
}  

Program.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Collections;
namespace bt18
{
    class 
Program
    
{
        static 
ArrayList list = new ArrayList();
        static 
Random rnd = new Random();
        static 
int TOCDO 700;

        static 
void Main(string[] args)
        {
            
Console.CursorVisible false;
            do
            {
                
NhanPhimBam();
                
TaoChu();
                
RoiChu();             
                
Thread.Sleep(TOCDO);
            } while (
KiemTraTiepTuc());         
        }

        static 
void RoiChu()
        {         
            
Console.Clear();
            for (
int i 0< list.Counti++)
            {
                ((
CDIEM)list[i]).DichXuong(1);
                ((
CDIEM)list[i]).Xuat();
            }
         
        }

        static 
void TaoChu()
        {
            
char c;
            
//do
            //{
            //    c = (char)(rnd.Next(65, 90));
            //} while(KiemTraChuTonTai(c));
            
= (char)(rnd.Next(6590));
            list.
Add(new CDIEM(rnd.Next(1Console.WindowWidth 1), 0c));
        }

        static 
bool KiemTraTiepTuc()
        {
            if (((
CDIEM)list[0]).KhoangCachY() > Console.WindowHeight)
                return 
false;
            return 
true;
        }

        static 
void NhanPhimBam()
        {         
            while (
Console.KeyAvailable)
            {
                
char cc Console.ReadKey(true).KeyChar;

                for (
int i 0< list.Counti++)
                {
                    if (((
CDIEM)list[i]).== cc)
                    {
                        list.
RemoveAt(i);
                    }
                }

            }            
        }
    }
}  

Nhập dòng chữ, cho chạy qua chạy lại trên màn hình console

Nhập dòng chữ, cho chạy qua chạy lại trên màn hình console



using System; 
using System
.Collections.Generic; 
using System
.Linq; 
using System
.Text; 
using System
.Threading; 
namespace vanviet
{ 
    class 
Program 
    
{ 
        static 
void Main(string[] args) 
        { 
            
string S; 
            
Console.Write("Nhap chuoi S: "); 
            
Console.ReadLine(); 
            
int l = (int)S.Length; 
             
            for (
int i 0<= Console.WindowWidthi++) 
            { 
                
Console.SetCursorPosition(i10); 
                
Console.WriteLine("{0}"S); 
                
Thread.Sleep(50); 
                
Console.Clear(); 
                if (
Console.KeyAvailable == true) 
                { 
                    
ConsoleKeyInfo k; 
                    
Console.ReadKey(); 
                    if (
k.Key == ConsoleKey.Escape) 
                        return; 
                } 
                if (
== Console.WindowWidth l) 
                { 
                    for (
int j Console.WindowWidth l>= 0j--) 
                    { 
                        
Console.SetCursorPosition(j10); 
                        
Console.WriteLine("{0}"S); 
                        
Thread.Sleep(50); 
                        
Console.Clear(); 
                        if (
== 0) 
                            
0; 
                        if (
Console.KeyAvailable == true) 
                        { 
                            
ConsoleKeyInfo k; 
                            
Console.ReadKey(); 
                            if (
k.Key == ConsoleKey.Escape) 
                                return; 
                        } 
                    } 
                } 
            } 

        } 
    }